Various embodiments of the present invention relate to the field of compiling, and more specifically, to a method and apparatus for processing a source file to generate an object file.
With the development of computer technology, there have emerged a large amount of programming languages. Moreover, source code in many programming languages involves various types of file formats. For example, regarding the C language, source code may comprise a source file (e.g. *.c file) and a header file (e.g. *.h file); for another example, regarding the C++ language, source code may comprise a source file (e.g. *.cpp file) and a header file (e.g. *.h file and *.hpp file).
Generally speaking, the source file may be used for saving concrete implementation (e.g. body code portion) of a program, while the header file may save an interface (e.g. data structure, definition of a function, etc.) of the program. The source file may reference the header file, for example, via “#include” in C and C++. Specifically, one source file may reference a plurality of header files, while one header file may be referenced by a plurality of source files. Therefore, there may exist complicated multiple-to-multiple reference relationships between source files and header files.
Typically developers will reference a plurality of header files in one source file (sometimes they might reference a header file which the source file actually does not need); at this point, when any one of the plurality of header files is updated (even if the updated header file is totally irrelevant to the source file), the source file needs to be re-compiled.
Note compiling a source file involves a number of processing steps. For example, front-end processing may comprise lexical analysis, syntax analysis, semantic analysis, intermediate code generating, etc., while back-end processing involves code optimizing, object code generating, etc. Therefore, it might take considerable time to compile only one source file.
On the other hand, with the complication of user requirements, a single programmer can hardly complete the development of an application program. Each compiler might develop dozens of and even more source files, and each source file might reference one or more header files. At this point, it might take dozens of minutes and even longer to re-compile all source code. In view of these problems, it demands prompt solution as to how to reduce the time needed to compile source code and increase the compiling efficiency.